package com.ruoyi.web.controller.applet;

import com.ruoyi.applet.order.domain.OrdOrder;
import com.ruoyi.applet.order.service.IOrdOrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 订单Controller
 * @author ruoyi
 * @date 2025-01-02
 */
@Controller
@RequestMapping("/applet/ordOrder")
public class OrdOrderController extends BaseController {
    
    private final String prefix = "applet/ordOrder";
    
    @Resource
    private IOrdOrderService ordOrderService;
    
    @RequiresPermissions("applet:ordOrder:view")
    @GetMapping()
    public String ordOrder() {
        return prefix + "/ordOrder";
    }
    
    /**
     * 查询订单列表
     */
    @RequiresPermissions("applet:ordOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrdOrder ordOrder) {
        startPage();
        List<OrdOrder> list = ordOrderService.selectOrdOrderList(ordOrder);
        return getDataTable(list);
    }
    
    /**
     * 导出订单列表
     */
    @RequiresPermissions("applet:ordOrder:export")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrdOrder ordOrder) {
        List<OrdOrder> list = ordOrderService.selectOrdOrderList(ordOrder);
        ExcelUtil<OrdOrder> util = new ExcelUtil<OrdOrder>(OrdOrder.class);
        return util.exportExcel(list, "订单数据");
    }
    
    /**
     * 新增订单
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
    
    /**
     * 新增保存订单
     */
    @RequiresPermissions("applet:ordOrder:add")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrdOrder ordOrder) {
        return toAjax(ordOrderService.insertOrdOrder(ordOrder));
    }
    
    /**
     * 修改订单
     */
    @RequiresPermissions("applet:ordOrder:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        OrdOrder ordOrder = ordOrderService.selectOrdOrderById(id);
        mmap.put("ordOrder", ordOrder);
        return prefix + "/edit";
    }
    
    /**
     * 修改保存订单
     */
    @RequiresPermissions("applet:ordOrder:edit")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrdOrder ordOrder) {
        return toAjax(ordOrderService.updateOrdOrder(ordOrder));
    }
    
    /**
     * 删除订单
     */
    @RequiresPermissions("applet:ordOrder:remove")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ordOrderService.deleteOrdOrderByIds(ids));
    }
}
